package org.common.netty;

import com.google.protobuf.GeneratedMessageV3;

import java.io.Serializable;

/**
 * 协议包pack定义
 */
public class Pack implements Serializable {
    private int cmdId;
    private byte[] data;

    public Pack() {
    }

    public Pack(int cmdId, byte[] data) {
        this.cmdId = cmdId;
        this.data = data;
    }
    public Pack(int cmdId, GeneratedMessageV3 protobuf) {
        this.cmdId = cmdId;
        this.data = protobuf.toByteArray();
    }
    public Pack(int cmdId, GeneratedMessageV3.Builder<?> builder) {
        this.cmdId = cmdId;
        this.data = builder.build().toByteArray();
    }

    public int getCmdId() {
        return cmdId;
    }

    public void setCmdId(int cmdId) {
        this.cmdId = cmdId;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    public int getDataLength() {
        return this.data == null ? 0 : this.data.length;
    }
}
